﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
<title>信息设置</title>
<script src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=Mk8h4HRD1DLT3wXGM6NbmObdP0rXV70D"></script>
<script type="text/javascript"
	src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>

<link href="css/pages.css" rel="stylesheet" />
<link href="css/MessageSet.css" rel="stylesheet" />
</head>
<body>
	<label for="roomname">办公室名称：</label>
	<input name="roomname" id="roomname" value="" placeholder="请输入办公室名称" />
	<label for="roomaddress">办公室地址：</label>
	<input name="roomaddress" id="roomaddress" value=""
		placeholder="请输入办公室地址" />
	<label>办公室坐标：</label>
	<input id="mygps" class="coord" readonly value=""
		placeholder="请在办公室内获取" />
	<span class="coord_ps">请使用手机网络，在办公室内获取。</span>
	<button id="submitinfo" onclick="submitinfo()">组长申请</button>
</body>
</html>
<!--微信sdk接口js-->
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
	var timestamp, nonceStr, signature, appid;
	var latitude; // 纬度，浮点数，范围为90 ~ -90
	var longitude; // 经度，浮点数，范围为180 ~ -180。
	var speed; // 速度，以米/每秒计
	var accuracy; // 位置精度
	var result;
	$.ajax({
		async : false,
		cache : false,
		type : 'POST',
		url : "WeChatAction_webweixin.action",
		data : {
			url : encodeURIComponent(location.href.split('#')[0]),
		//	url:location.href.split('#')[0]
		},
		dataType : "json",
		success : function(data) {
			msg = eval("(" + data + ")");
			if (msg.msg == 1) {
				timestamp = msg.timestamp;
				nonceStr = msg.nonceStr;
				signature = msg.signature;
				appid = msg.appId;
			} else {

			}
		},
		error : function() {
			alert("1111出现异常！！");
		}
	});

	wx.config({
		debug : false,
		appId : appid,
		timestamp : timestamp,
		nonceStr : nonceStr,
		signature : signature,
		jsApiList : [ 'checkJsApi', 'getLocation' ]
	});

	wx.error(function(res) {
		alert("出错了！" + res.errMsg);
	});
	function Location() {
		wx.ready(function() {
			wx.checkJsApi({
				jsApiList : [ 'getLocation' ],
				success : function(res) {
				}
			});
			//获取地理信息
			wx.getLocation({
				type : 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
				success : function(res) {
					latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
					longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
					speed = res.speed; // 速度，以米/每秒计
					accuracy = res.accuracy; // 位置精度
				}
			});

		});

	};
</script>
<script src="Scripts/wechatsdk/zepto.min.js"></script>
<script src="Scripts/ChangeLocation.js"></script>
<script type="text/javascript">
	var url = location.href.split('#')[0];
	
	var start = url.indexOf("code=");

	var end = url.indexOf("&");

	var code = url.substring(start + 5, end);

//	var point=new Object();

	$(function() {
		Location();
	});

	/* function GPSToBaidu(lngX,latY){  
	    var gps_point=new BMap.Point(lngX,latY);  
	    BMap.Convertor.translate(gps_point,0,function(bd_point){          
	       //  alert("lng:"+bd_point.lng+" lat:"+bd_point.lat); 
	       point.lng = bd_point.lng;
	       point.lat = bd_point.lat;
	       return point;
	    });  
	}  
	
	function MapabcEncryptToBdmap(gg_lat, gg_lon)    
	 {    
 
	     var x_pi = 3.14159265358979324 * 3000.0 / 180.0;  
	     var x = new Number(gg_lon);  
	     var y = new Number(gg_lat);    
	     var z =  Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);    
	     var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);    
	     var bd_lon = z * Math.cos(theta) + 0.0065;    
	     var bd_lat = z * Math.sin(theta) + 0.006;   
	     point.lng=bd_lon;  
	     point.lat=bd_lat;
	     
	     alert("-1:"+point.lng+","+point.lat);  
	     return point;  
	 }     */

	//	var ggPoint = new BMap.Point(longitude,latitude);
	//百度地图API功能 获取地址
	var map = new BMap.Map("allmap");
	//	map.centerAndZoom(ggPoint, 15);
	//   map.addControl(new BMap.NavigationControl());
	/* var longitude, latitude;  
	 navigator.geolocation.getCurrentPosition(function (position) {  
	   longitude = position.coords.longitude;
	   latitude = position.coords.latitude;  
	   alert("===="+latitude);
	});   */
	//	var points2;
	var addrs;

	setTimeout(function() {
		var gpsPoint =  new BMap.Point(longitude, latitude); 
		BMap.Convertor.translate(gpsPoint, 0, function(point) {
			var geoc = new BMap.Geocoder();
			geoc.getLocation(point, function(rs) {
				var addComp = rs.addressComponents;
				addrs = addComp.province + ", " + addComp.city + ", "
						+ addComp.district + ", " + addComp.street + ", "
						+ addComp.streetNumber;
				$(function() {
					//	alert(addrs);
					$("#mygps").val(addrs);
				})
				// alert(addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);  
				//   alert(addComp.streetNumber);
			});
		});
	}, 3000);

	// 百度地图API功能 获取地址
	/* function address() {
	   var geolocation = new BMap.Geolocation();
	   geolocation.getCurrentPosition(function (r) {
	      if (this.getStatus() == BMAP_STATUS_SUCCESS) {
	          var mk = new BMap.Marker(r.point);
	     	  map.addOverlay(mk);
	          map.panTo(r.point);
	          alert('您的位置：' + r.point.lng + ',' + r.point.lat);
	     }
	     else {
	         alert("坐标经纬度未获取成功，请刷新页面。");
	      }
	    }, { enableHighAccuracy: true })
	}; */

	function submitinfo() {
		var namea = $("#roomname").val();
		var addressa = $("#roomaddress").val();
		if ($("#roomname").val().length <= 0
				|| $("#roomaddress").val().length <= 0) {
			alert("名称或地址不能为空");
			return;
		} else {

			$.ajax({
				type : "POST",
				url : 'WeChatAction_message_set.action',
				// url: "ImGroup",
				//  data: "OpenID=" + openid + "&UnitName=" + namea + "&Address=" + addressa + "&Point=" + coorda,
				//dataType:"json",
				data : {
					name : $("#roomname").val(),
					addr : $("#roomaddress").val(),
					lng : longitude,
					lat : latitude,
					code : code
				},
				dataType : "json",
				async : false,
				success : function(data) {
					msg = eval("(" + data + ")");
					if (msg.msg == true) {
						alert("登记成功！等待管理员进行审核！");
						WeixinJSBridge.call("closeWindow");
					} else {
						alert("您还没有注册，请先注册！");
					}
				},
				error : function(err) {
					alert("系统异常，请稍后再试！")
				}
			})
		}
	};

	//输入的值不能为空
	/*     function valz() {
	 if ($("#roomname").val().length <= 0 || $("#roomaddress").val().length <= 0 || $('.coord').val().length <= 0) {
	 alert("名称或地址不能为空");
	 }
	 }; */
</script>